<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        body li {
            list-style: none;
        }

        .tab_switch {
            width: 384px;
            height: 270px;
            margin: 0 auto;
        }

        .tab_switch ul {
            width: 384px;
            height: 30px;
            padding: 0;
            margin: 0;
        }

        .tab_switch ul li {
            width: 96px;
            height: 30px;
            background-color: gainsboro;
            border: 1px solid gray;
            box-sizing: border-box;
            font-size: 12px;
            font-weight: bold;
            line-height: 30px;
            text-align: center;
            float: left;
        }

        .tab_switch ul li:first-child {
            background-color: gray;
        }

        .tab_switch .box {
            width: 200px;
            height: 40px;
            text-align: center;
            clear: both;
        }

        .tab_switch .box p {
            display: none;
        }

        .tab_switch .box p:first-child {
            display: block;
        }
    </style>
</head>

<body>
    <div class="tab_switch">
        <ul>
            <li>国内新闻</li>
            <li>国外新闻</li>
            <li>国际新闻</li>
            <li>娱乐新闻</li>
        </ul>
        <div class="box">
            <p>国内新闻</p>
            <p>国外新闻</p>
            <p>国际新闻</p>
            <p>娱乐新闻</p>
        </div>
</body>

</html>
<script>
    var ul = document.getElementsByTagName("ul")[0]
    var li = document.getElementsByTagName("li");
    var p = document.getElementsByTagName("p");

    for (let i = 0; i < li.length; i++) {
        li[i].index = i;
        li[i].addEventListener("mouseover", function () {
            li[0].style.background = "gainsboro";
            for (var j = 0; j < li.length; j++) {
                p[j].style.display = "none";
            }
            this.style.background = "gray";
            p[this.index].style.display = "block";
        })
        li[i].addEventListener('mouseout', () => {
            li[i].style.background = "gainsboro";
        })
    }
    ul.addEventListener('mouseout', () => {
        li[0].style.background = "gray";
        for (var j = 0; j < li.length; j++) {
            p[j].style.display = "none";
        }
        p[0].style.display = "block";
    })
</script>